/**
 * 单例模式
 */

import assert from "assert"


interface Db {
  query (): Array<any>
}

class Mysql implements Db {
  private static instance: Mysql

  private constructor () {}

  public query (): Array<any> {
    return []
  }

  static getInstance (): Db {
    if (!this.instance) {
      this.instance = new Mysql()
    }
    return this.instance
  }
}

function main () {
  let m1: Mysql = Mysql.getInstance()
  let m2: Mysql = Mysql.getInstance()
  assert(m1 == m2, "m1 should be equal to m2")
}

main()